using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Text;

namespace Data_Access_Tier
{
	public class HRM_RECRUITMENTData : DatabaseObjectBase
	{
		public HRM_RECRUITMENTData()
		{
			Initialize(true);
		}
		public HRM_RECRUITMENTData(Boolean newConnection)
		{
			Initialize(newConnection);
		}

		public Int32 HRM_RECRUITMENT_Insert(String RecruitmentCode, String RecruitmentName, DateTime FromDate, DateTime ToDate, Int32 Quantity, String DecideNumber, String FilePath, Int32 Status, String Description)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.InsertCommand = new SqlCommand("HRM_RECRUITMENT_Insert");
				_dbadapter.InsertCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.InsertCommand.Connection = _dbconn;
				_trans = _dbconn.BeginTransaction();
				_dbadapter.InsertCommand.Transaction = _trans;
				_dbadapter.InsertCommand.Parameters.Clear();
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@RecruitmentCode", SqlDbType.VarChar, 20));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@RecruitmentName", SqlDbType.NVarChar, 100));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@FromDate", SqlDbType.DateTime));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@ToDate", SqlDbType.DateTime));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Quantity", SqlDbType.Int));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@DecideNumber", SqlDbType.VarChar, 20));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@FilePath", SqlDbType.NVarChar, 255));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Status", SqlDbType.Int));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Description", SqlDbType.NVarChar, 255));
				_dbadapter.InsertCommand.Prepare();
				SqlString RecruitmentCodeSQL = RecruitmentCode;
				_dbadapter.InsertCommand.Parameters["@RecruitmentCode"].Value = RecruitmentCodeSQL;
				SqlString RecruitmentNameSQL = RecruitmentName;
				_dbadapter.InsertCommand.Parameters["@RecruitmentName"].Value = RecruitmentNameSQL;
				SqlDateTime FromDateSQL = SqlDateTime.Null;
				if (FromDate > DateTime.MinValue)
				{
					try
					{
						FromDateSQL = FromDate;
					}
					catch (Exception eFromDate)
					{
						String FromDateMessage = eFromDate.Message;
						FromDateSQL = SqlDateTime.Null;
					}
				}
				_dbadapter.InsertCommand.Parameters["@FromDate"].Value = FromDateSQL;
				SqlDateTime ToDateSQL = SqlDateTime.Null;
				if (ToDate > DateTime.MinValue)
				{
					try
					{
						ToDateSQL = ToDate;
					}
					catch (Exception eToDate)
					{
						String ToDateMessage = eToDate.Message;
						ToDateSQL = SqlDateTime.Null;
					}
				}
				_dbadapter.InsertCommand.Parameters["@ToDate"].Value = ToDateSQL;
				SqlInt32 QuantitySQL = Quantity;
				_dbadapter.InsertCommand.Parameters["@Quantity"].Value = QuantitySQL;
				SqlString DecideNumberSQL = DecideNumber;
				_dbadapter.InsertCommand.Parameters["@DecideNumber"].Value = DecideNumberSQL;
				SqlString FilePathSQL = FilePath;
				_dbadapter.InsertCommand.Parameters["@FilePath"].Value = FilePathSQL;
				SqlInt32 StatusSQL = Status;
				_dbadapter.InsertCommand.Parameters["@Status"].Value = StatusSQL;
				SqlString DescriptionSQL = Description;
				_dbadapter.InsertCommand.Parameters["@Description"].Value = DescriptionSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.InsertCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_RECRUITMENT_Insert: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_RECRUITMENT_Insert: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.InsertCommand != null)
					_dbadapter.InsertCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 HRM_RECRUITMENT_Update(String RecruitmentCode, String RecruitmentName, DateTime FromDate, DateTime ToDate, Int32 Quantity, String DecideNumber, String FilePath, Int32 Status, String Description)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.UpdateCommand = new SqlCommand("HRM_RECRUITMENT_Update");
				_dbadapter.UpdateCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.UpdateCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.UpdateCommand.Transaction = _trans;

				_dbadapter.UpdateCommand.Parameters.Clear();
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@RecruitmentCode", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@RecruitmentName", SqlDbType.NVarChar, 100));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@FromDate", SqlDbType.DateTime));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@ToDate", SqlDbType.DateTime));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Quantity", SqlDbType.Int));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@DecideNumber", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@FilePath", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Status", SqlDbType.Int));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Description", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Prepare();
				SqlString RecruitmentCodeSQL = RecruitmentCode;
				_dbadapter.UpdateCommand.Parameters["@RecruitmentCode"].Value = RecruitmentCodeSQL;
				SqlString RecruitmentNameSQL = RecruitmentName;
				_dbadapter.UpdateCommand.Parameters["@RecruitmentName"].Value = RecruitmentNameSQL;
				SqlDateTime FromDateSQL = SqlDateTime.Null;
				if (FromDate > DateTime.MinValue)
				{
					try
					{
						FromDateSQL = FromDate;
					}
					catch (Exception eFromDate)
					{
						String FromDateMessage = eFromDate.Message;
						FromDateSQL = SqlDateTime.Null;
					}
				}
				_dbadapter.UpdateCommand.Parameters["@FromDate"].Value = FromDateSQL;
				SqlDateTime ToDateSQL = SqlDateTime.Null;
				if (ToDate > DateTime.MinValue)
				{
					try
					{
						ToDateSQL = ToDate;
					}
					catch (Exception eToDate)
					{
						String ToDateMessage = eToDate.Message;
						ToDateSQL = SqlDateTime.Null;
					}
				}
				_dbadapter.UpdateCommand.Parameters["@ToDate"].Value = ToDateSQL;
				SqlInt32 QuantitySQL = Quantity;
				_dbadapter.UpdateCommand.Parameters["@Quantity"].Value = QuantitySQL;
				SqlString DecideNumberSQL = DecideNumber;
				_dbadapter.UpdateCommand.Parameters["@DecideNumber"].Value = DecideNumberSQL;
				SqlString FilePathSQL = FilePath;
				_dbadapter.UpdateCommand.Parameters["@FilePath"].Value = FilePathSQL;
				SqlInt32 StatusSQL = Status;
				_dbadapter.UpdateCommand.Parameters["@Status"].Value = StatusSQL;
				SqlString DescriptionSQL = Description;
				_dbadapter.UpdateCommand.Parameters["@Description"].Value = DescriptionSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.UpdateCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_RECRUITMENT_Update: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_RECRUITMENT_Update: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.UpdateCommand != null)
					_dbadapter.UpdateCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 HRM_RECRUITMENT_Disable(String RecruitmentCode, ref Boolean Enabled)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.UpdateCommand = new SqlCommand("HRM_RECRUITMENT_Disable");
				_dbadapter.UpdateCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.UpdateCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.UpdateCommand.Transaction = _trans;

				_dbadapter.UpdateCommand.Parameters.Clear();
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@RecruitmentCode", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@enabled", SqlDbType.Bit));
				_dbadapter.UpdateCommand.Prepare();
				SqlString RecruitmentCodeSQL = RecruitmentCode;
				_dbadapter.UpdateCommand.Parameters["@RecruitmentCode"].Value = RecruitmentCodeSQL;
				_dbadapter.UpdateCommand.Parameters["@enabled"].Direction = ParameterDirection.Output;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.UpdateCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_RECRUITMENT_Disable: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_RECRUITMENT_Disable: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.UpdateCommand != null)
					_dbadapter.UpdateCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 HRM_RECRUITMENT_Delete(String RecruitmentCode)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.DeleteCommand = new SqlCommand("HRM_RECRUITMENT_Delete");
				_dbadapter.DeleteCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.DeleteCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.DeleteCommand.Transaction = _trans;

				_dbadapter.DeleteCommand.Parameters.Clear();
				_dbadapter.DeleteCommand.Parameters.Add(new SqlParameter("@RecruitmentCode", SqlDbType.VarChar, 20));
				_dbadapter.DeleteCommand.Prepare();
				SqlString RecruitmentCodeSQL = RecruitmentCode;
				_dbadapter.DeleteCommand.Parameters["@RecruitmentCode"].Value = RecruitmentCodeSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.DeleteCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_RECRUITMENT_Delete: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_RECRUITMENT_Delete: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.DeleteCommand != null)
					_dbadapter.DeleteCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 HRM_RECRUITMENT_Save(String RecruitmentCode, String RecruitmentName, DateTime FromDate, DateTime ToDate, Int32 Quantity, String DecideNumber, String FilePath, Int32 Status, String Description)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.UpdateCommand = new SqlCommand("HRM_RECRUITMENT_Save");
				_dbadapter.UpdateCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.UpdateCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.UpdateCommand.Transaction = _trans;

				_dbadapter.UpdateCommand.Parameters.Clear();
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@RecruitmentCode", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@RecruitmentName", SqlDbType.NVarChar, 100));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@FromDate", SqlDbType.DateTime));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@ToDate", SqlDbType.DateTime));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Quantity", SqlDbType.Int));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@DecideNumber", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@FilePath", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Status", SqlDbType.Int));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Description", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Prepare();
				SqlString RecruitmentCodeSQL = RecruitmentCode;
				_dbadapter.UpdateCommand.Parameters["@RecruitmentCode"].Value = RecruitmentCodeSQL;
				SqlString RecruitmentNameSQL = RecruitmentName;
				_dbadapter.UpdateCommand.Parameters["@RecruitmentName"].Value = RecruitmentNameSQL;
				SqlDateTime FromDateSQL = SqlDateTime.Null;
				if (FromDate > DateTime.MinValue)
				{
					try
					{
						FromDateSQL = FromDate;
					}
					catch (Exception eFromDate)
					{
						String FromDateMessage = eFromDate.Message;
						FromDateSQL = SqlDateTime.Null;
					}
				}
				_dbadapter.UpdateCommand.Parameters["@FromDate"].Value = FromDateSQL;
				SqlDateTime ToDateSQL = SqlDateTime.Null;
				if (ToDate > DateTime.MinValue)
				{
					try
					{
						ToDateSQL = ToDate;
					}
					catch (Exception eToDate)
					{
						String ToDateMessage = eToDate.Message;
						ToDateSQL = SqlDateTime.Null;
					}
				}
				_dbadapter.UpdateCommand.Parameters["@ToDate"].Value = ToDateSQL;
				SqlInt32 QuantitySQL = Quantity;
				_dbadapter.UpdateCommand.Parameters["@Quantity"].Value = QuantitySQL;
				SqlString DecideNumberSQL = DecideNumber;
				_dbadapter.UpdateCommand.Parameters["@DecideNumber"].Value = DecideNumberSQL;
				SqlString FilePathSQL = FilePath;
				_dbadapter.UpdateCommand.Parameters["@FilePath"].Value = FilePathSQL;
				SqlInt32 StatusSQL = Status;
				_dbadapter.UpdateCommand.Parameters["@Status"].Value = StatusSQL;
				SqlString DescriptionSQL = Description;
				_dbadapter.UpdateCommand.Parameters["@Description"].Value = DescriptionSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.UpdateCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_RECRUITMENT_Save: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_RECRUITMENT_Save: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.UpdateCommand != null)
					_dbadapter.UpdateCommand.Dispose();
				CloseConnection();
			}
		}
		public DataSet HRM_RECRUITMENT_GetList()
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.SelectCommand = new SqlCommand("HRM_RECRUITMENT_GetList");
				_dbadapter.SelectCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.SelectCommand.Connection = _dbconn;
				_dbadapter.SelectCommand.Parameters.Clear();
				_dbadapter.SelectCommand.Prepare();
				_dbadapter.Fill(_data);

				return _data;
			}
			catch (SqlException e)
			{
				throw new Exception("SQL Error: HRM_RECRUITMENT_GetList: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.SelectCommand != null)
					_dbadapter.SelectCommand.Dispose();
				CloseConnection();
			}
		}
		public DataSet HRM_RECRUITMENT_Get(String RecruitmentCode)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.SelectCommand = new SqlCommand("HRM_RECRUITMENT_Get");
				_dbadapter.SelectCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.SelectCommand.Connection = _dbconn;
				_dbadapter.SelectCommand.Parameters.Clear();
				_dbadapter.SelectCommand.Parameters.Add(new SqlParameter("@RecruitmentCode", SqlDbType.VarChar, 20));
				_dbadapter.SelectCommand.Prepare();
				SqlString RecruitmentCodeSQL = RecruitmentCode;
				_dbadapter.SelectCommand.Parameters["@RecruitmentCode"].Value = RecruitmentCodeSQL;
				_dbadapter.Fill(_data);

				return _data;
			}
			catch (SqlException e)
			{
				throw new Exception("SQL Error: HRM_RECRUITMENT_Get: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.SelectCommand != null)
					_dbadapter.SelectCommand.Dispose();
				CloseConnection();
			}
		}
	}
}
